from email.policy import default
from tabnanny import verbose

from django.db import models
from django.urls import reverse
# 数据迁移命令；python manage.py makemigrations app4 # 为app4生成新的迁移文件
# python manage.py migrate app4        # 应用迁移，创建UserBaseInfo4表

# Create your models here.
class App4UserBaseInfo(models.Model):
    id = models.AutoField(verbose_name = '编号',primary_key=True)
    username = models.CharField(verbose_name= '用户名称', max_length=30)
    password = models.CharField(verbose_name= '密码', max_length=20)
    status = models.CharField(verbose_name= '状态', max_length=1)
    createdate = models.DateTimeField(verbose_name= '创建日期', db_column='createDate')

    def __str__(self):
        return str(self.id)
    class Meta:
        #managed = False # 为false数据迁移的时候不需要创建，
        verbose_name='人员基本信息'
        db_table='UserBaseInfo4'

class DepartInfo(models.Model):
    id = models.AutoField(verbose_name='部门编号',primary_key=True)
    departname = models.CharField(verbose_name='部门名称',max_length=30)
    createdate = models.DateTimeField(verbose_name='创建日期',db_column='createDate')

class UserExtraInfo(models.Model):
    id = models.AutoField(verbose_name='扩展编号',primary_key=True)
    username = models.CharField(verbose_name='用户名称',max_length=30)
    truename = models.CharField(verbose_name='真实姓名',max_length=30)
    sex = models.IntegerField(verbose_name='性别')
    salary = models.DecimalField(verbose_name='薪水',max_digits=8,decimal_places=2) # decimal_places小数的最大位数
    department = models.CharField(verbose_name='部门',max_length=20)
    age = models.IntegerField(verbose_name='年龄')
    status = models.CharField(verbose_name='状态',max_length=1)
    # auto_now_add：字段值设置创建时的时间，后期不能修改
    createdate = models.DateTimeField(verbose_name='创建日期',db_column='createDate',auto_now_add=True)
    memo = models.TextField(verbose_name='备注',blank=True,null=True)
    # 一对一 返回关联两张表的外键, CASCADE:删除基本信息时把扩展信息一起删除，级联删除
    user = models.OneToOneField(App4UserBaseInfo,on_delete=models.CASCADE)
    # 一对多 返回关联两张表的外键depart
    depart = models.ForeignKey(DepartInfo,default="",on_delete=models.CASCADE)

class SkillInfo(models.Model):
    id = models.AutoField(verbose_name='技能编号',primary_key=True)
    skillname = models.CharField(verbose_name='特长',max_length=30)
    createdate = models.DateTimeField(verbose_name='创建日期',db_column='createDate')
    user = models.ManyToManyField(UserExtraInfo,db_table="user_skill")

class CardInfo(models.Model):
    id = models.AutoField(verbose_name='编号',primary_key=True)
    cardno = models.CharField(verbose_name='卡号',max_length=30)
    bank = models.CharField(verbose_name='所属银行',max_length=30)
    user = models.ForeignKey(App4UserBaseInfo,related_name='usercard',on_delete=models.CASCADE)
    def __str__(self):
        return str(self.id)
    class Meta:
        managed = True
        verbose_name = '用户卡信息'
        db_table = 'CardInfo'
